home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
telecomm
/
uemlsrc.arc
/
kermit.c
< prev
next >
Wrap
C/C++ Source or Header
|
1987-08-24
|
21KB
|
608 lines
/* kermit.c support routines and main entry point for Uemail file transfer
* functions. Kermit send, receive, get, put, finish, and bye supported.
* Buffer logging and direct ASCII transfer also available. All actions are
* ASCII 7 bit files. Transfers are made into and out of Uemail buffers.
*/
#include <stdio.h>
#include <osbind.h>
#include <ctype.h>
#include "ed.h"
#include "kermit.h"
int emacsfile; /* if TRUE then \r become \n on ASCII transfers */
char getfiln[NFILEN]; /* name for remote file get or put */
char deflow[] = "XON/XOFF";
static unsigned char *tsr_ptr = (char *)0x00fffa2d; /* See St internals */
static long *hz_200 = (long *)0x000004ba;
int *aaddress(); /* thanks Jwahar R. Bammi for this line A code */
int *aline_addr; /* Ptr to base of Aline variables */
int sav_row, sav_col;
int flow = DEFLO; /* default flow control */
int defbaud = 7;
int bps = DEFBPS;
unsigned long *hpterm; /* HOST */
/* KERMIT CTRL command prompt for action and switch to appropriate state.
* Returns TRUE on success. !TRUE on failures. Bound to ^_ and HELP on ST.
*/
kermit(flg, _n)
register int flg, _n;
{
static char command[9]; /* command */
register char key;
register int owf;
owf = curwp->w_flag; /* save for redraw */
if ((_n=mlreply("Kermit-ST> ",command,8)) != TRUE)
return(_n==FALSE ? FALSE : ABORT);
/* Initialize these values */
/* Hope the first packet will get across OK */
eol = CR; /* EOL for outgoing packets */
quotech = '#'; /* Standard control-quote char "#" */
pad = 0; /* No padding */
padchar = '\0'; /* Use null if any padding wanted */
timint = DEFTIME; /* Default timeout */
parity = DEFPAR; /* Default to no parity */
logfile = 0; /* Capture flag */
emacsfile = 0; /* Trans to emacs (no EOF) */
en8quote(FALSE);
key = tolower(command[0]);
switch (key)
{
case 'b': /* B = Bye */
if(mlyesno("Logout remote")==TRUE)
if(gencmdsw('L')==FALSE)
{
mlwrite("Remote does not ACK BYE");
(*term.t_beep)();
return(FALSE);
}
return(TRUE); /* No update */
case 'c': /* C = Connect command */
connect();
break;
case 'e': /* E = transmit to GNU_EMACS command */
if(usebuffer(NULL,NULL) != TRUE)
return(FALSE);
gotobob(NULL, 1);
update();
mlwrite("[Transmitting %s to remote EMACS]",curbp->b_bna
me);
emacsfile = 1;
trans();
emacsfile = 0;
connect();
break;
case 'f': /* F = Finish */
if(gencmdsw('F')==FALSE)
{
mlwrite("Remote does not ACK FINISH");
(*term.t_beep)();
return(FALSE);
}
return(TRUE); /* No update */
case 'g': /* G = Get command */
if((_n=mlreply("Remote filename: ",getfiln,NFILEN))!=TRU
E)
return(_n);
if(usebuffer(NULL,NULL) != TRUE)
return(FALSE);
gotoeob(NULL, 1);
update();
if((_n=getsw()) == FALSE)
{
(*term.t_beep)();
mlreply("Get failed. Type <CR>",command,2);
}
break;
case 'l': /* L = Log session */
if(usebuffer(NULL,NULL) != TRUE)
return(FALSE);
gotoeob(NULL, 1);
logfile = TRUE;
connect();
break;
case 'r': /* R = Receive command */
if(usebuffer(NULL,NULL) != TRUE)
return(FALSE);
gotoeob(NULL, 1);
update();
if((_n=recsw()) == FALSE)
{
(*term.t_beep)();
mlreply("Receive failed. Type <CR>",command,2);
}
break;
case 'p': /* P = Put command */
if((_n=mlreply("Remote filename: ",getfiln,NFILEN))!=TRU
E)
return(_n);
case 's': /* S = Send command */
if(usebuffer(NULL,NULL) != TRUE)
return(FALSE);
if (key == 's')
strcpy(getfiln,curbp->b_bname);
gotobob(NULL, 1);
update();
if((_n=sendsw()) == FALSE)
{
if (key == 's')
mlwrite("Send failed");
else
mlwrite("Put failed");
(*term.t_beep)();
}
if (key == 's')
connect();
break;
case 't': /* T = transmit command */
if(usebuffer(NULL,NULL) != TRUE)
return(FALSE);
gotobob(NULL, 1);
update();
mlwrite("[Transmitting: %s]",curbp->b_bname);
trans();
connect();
break;
default:
mlwrite("Connect, Send, Receive, Get, Put, Finish, Bye\
, Log, Transfer");
return(FALSE);
}
/* Restore controlling tty's modes */
owf |= WFHARD; owf |= WFMODE;
curwp->w_flag |= owf;
sgarbf = TRUE; /* we know screen is garbage after connect */
update();
return(TRUE);
}
/*
* c o n n e c t
*
* Establish a virtual terminal connection with the remote host, over an
* assigned tty line.
*/
connect()
{
register int c;
setterm(REMOTE);
while (1)
{
if (Bconstat(2))
if(readcon() == FALSE)
break;
if (Bconstat(1))
{
c=readaux();
ttputc(c);
if (logfile)
{
if (c=='\n')
{
lnewline();
continue;
}
if (c=='\r')
continue;
linsert(1,c);
}
}
}
setterm(HOST);
return(FALSE);
}
/* set up terminal's screen and allow it to be saved for later.
*/
setterm(f)
int f;
{
static char scrbase[0x7d10];
static unsigned char firsttime =